<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>v-on实例</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <script type="text/javascript" src="../assets/js/vue.js"></script>
</head>
<body>    
    <h1>v-on实例</h1>
    <a href="../index.html">返回</a>
    <hr/>
    <div id="app">
        本场得分:{{score}}
        <button v-on:click="addscore">加1分</button>
        <button @click="calscore">减1分</button><br/>
        <input type="text" v-on:keyup.enter="onenter" v-model="score2"  />

        <hr/>
        键盘码: 按上键(38)和下键(40)<br/>

        <input type="text" v-on:keyup.38="demof9" v-on:keyup.40="demof8" v-model="nval" />
        <img src="../assets/imgs/20170227001137.jpg" />
    </div>
    <script>
        var app= new Vue({
            el:"#app",
            data:{
               score:0,
               score2:10,
               nval:10
            },
            methods:{
                addscore:function(){
                    this.score++;
                },
                calscore:function(){
                    this.score--;
                },
                onenter:function(){
                    this.score = this.score+parseInt(this.score2);
                },
                demof9:function(){
                    this.nval=this.nval+parseInt(120);
                },
                demof8:function(){
                    this.nval = this.nval-parseInt(11);                    
                    if(this.nval<=0)
                        this.mval=0;
                }
            }
        })
    </script>
</body>
</html>